import random
import time


class Superman:
    def __init__(self,name, blood, aggr):
        self.name = name
        self.blood = blood
        self.aggr = aggr

    def __str__(self):
        return f"角色血量 {self.blood}    角色攻击力 {self.aggr}"


class SupermanManage:
    def __init__(self):
        self.l = []

    def add_superman(self):
        names = ["小张", "小李", "小王", "小唐", "小孙", "小孔", "小董", "小高", "小刘", "小徐"]
        for i in range(10):
            s = Superman(names[i], random.randint(3000,  5000), random.randint(100, 300))
            d = {
                "名字": s.name,
                "血量": s.blood,
                "攻击力": s.aggr
            }
            self.l.append(d)

    def show_superman(self):
        for e in self.l:
            print(e)

    def attack(self):
        count = 1
        while True:
            for i in range(len(self.l)-1, -1, -1):
                if self.l[i]["血量"] <= 0:
                    print(f"{self.l[i]['名字']}  血量为：{self.l[i]['血量']}    判定死亡")
                    self.l.pop(i)
                    print(f"剩余{len(self.l)}人")
                    if len(self.l) == 1:
                        break
            else:
                if len(self.l) > 1:
                    print(f"第{count}轮攻击")
                    self.l[0]["血量"] -= self.l[-1]["攻击力"]
                    for i in range(len(self.l)-1):
                        self.l[i+1]["血量"] -= self.l[i]["攻击力"]
                    time.sleep(0.1)
                    print(f"第{count}轮攻击结束")
                    print(f"当前英雄状态{self.l}")
                    count += 1
                else:
                    break


def get_time(f):
    def show_time():
        start = time.time()
        f()
        end = time.time()
        print(f"程序用时{end - start}")
    return show_time


@get_time
def main():
    sm = SupermanManage()
    sm.add_superman()
    sm.show_superman()
    print("# "*20)
    sm.attack()
    sm.show_superman()


if __name__ == '__main__':
    main()

